package com.pxmeta.app.controller.chat;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.pxmeta.app.controller.chat.vo.friend.AddFriendVO;
import com.pxmeta.chat.entity.vo.FriendsVO;
import com.pxmeta.chat.service.HuanxinService;
import com.pxmeta.common.core.domain.AjaxResult;
import com.pxmeta.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/chat/friend")
@RequiredArgsConstructor
@Api(tags = "聊天好友",value = "聊天好友")
// todo 记录本地表
public class FriendController {

    private final HuanxinService huanxinService;


    @SaCheckLogin
    @PostMapping("/addFriend")
    @ApiOperation("添加好友")
    public AjaxResult addFriend(@RequestBody AddFriendVO vo){
        String username = SecurityUtils.getUsername();
        huanxinService.addFriend(username, vo.getFriendUsername());
        return AjaxResult.success();
    }

    @SaCheckLogin
    @DeleteMapping("/removeFriend")
    @ApiOperation("删除好友")
    public AjaxResult removeFriend(@RequestBody AddFriendVO vo){
        String username = SecurityUtils.getUsername();
        huanxinService.removeFriend(username, vo.getFriendUsername());
        return AjaxResult.success();
    }

    @SaCheckLogin
    @GetMapping("/getFriends")
    @ApiOperation("获取好友列表")
    public AjaxResult<FriendsVO> getFriends(Integer page, Integer size, String keyword){
        String username = SecurityUtils.getUsername();
        FriendsVO friends = huanxinService.getFriends(username, page, size, keyword);
        return AjaxResult.success(friends);
    }

}
